const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});

const db=cloud.database();

exports.main = async (event, context) => {
  const {account}=event.data;
  try{
      const class_num=await db.collection("teacher").where({
        account:account,
      }).field({
        grade:true,
        // Class:true,
        college:true
      }).get();
      if(class_num.data.length==1){
        const userlist=await db.collection("student").where({
          check_status:3,
          // Class:class_num.data[0].Class,
          grade:class_num.data[0].grade,
          college:class_num.data[0].college,
          application_status:1
        }).field({
          name:true,
          account:true,
          check_status:true,
          family_background:true,
          political_thought:true,
          learning_condition:true,
          innovation_ability:true,
          social_practice:true,
        }).get();
        if(userlist.data.length!=0){
          return {success:true,message:userlist.data}
        }else{
          return{success:false,message:"获取失败0"+userlist.data.length}
        }
      }else{
        return{success:false,message:"获取失败1"}
      }
  }catch(error){
      return{success:false,message:account}
  }
};